package com.orientation.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.orientation.entity.Student;
import com.orientation.vo.StudentPageVo;
import com.orientation.vo.StudentVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 * 学生 Mapper 接口
 * </p>
 *
 * @author xuandian
 * @since 2022-3-9
 */

public interface StudentMapper extends BaseMapper<Student> {


    @Select(value = "select * from t_student where sid=#{id}")
    @Results(id = "stuMap", value = {
            @Result(property = "myCollege", column = "college_id", one = @One(select = "com.orientation.mapper.CollegeMapper.selectById")),
            @Result(property = "myMajor", column = "major_id", one = @One(select = "com.orientation.mapper.MajorMapper.selectById")),
            @Result(property = "myClass", column = "class_id", one = @One(select = "com.orientation.mapper.ClassMapper.selectById"))
    })
    StudentVo findStudentVoById(Student id);

    /**
     * 导出文件
     *
     * @return
     */
    @Select(value = "select * from t_student where CLASS_ID is not null")
    @ResultMap(value = "stuMap")
    List<StudentVo> findAllStudentVoAllocated();


    @Select(value = {"<script>", "select s.*,c.college_name,m.major_name from t_student s ",
            "left join t_college c on s.college_id = c.sid ",
            "left join t_major m on s.major_id = m.sid ",
            "where s.deleted=0 ",
            "<when test='collegeName!=null'>",
            "and c.college_name like CONCAT('%', #{collegeName},'%')",
            "</when>",
            "<when test='majorName!=null'>",
            "and m.major_name like CONCAT('%', #{majorName},'%')",
            "</when>",
            "<when test='studentName!=null'>",
            "and s.student_name like CONCAT('%', #{studentName},'%')",
            "</when>",
            "<when test='grade!=null'>",
            "and s.grade = #{grade}",
            "</when>",
            "order by c.college_name,m.major_name",
            "</script>"})
    IPage<StudentPageVo> findStudentVoPage(Page<StudentPageVo> page, String collegeName, String majorName, String studentName, String grade);

    void deleteCarProjects(List<String> allCarProjectIds);
}